#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  03-kylinsec_release.sh
# Version	:  2.0
# Date		:  2024/04/26
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinsec.com.cn
# Function	:  kylinsec_release测试
# Out		:
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="kylinsec_release测试"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB() {
    return $TPASS
}

## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB() {
    return $TPASS
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB() {
    testcase_1
    return $TPASS
}

## TODO : kylinsec_release测试
testcase_1() {
    which ks-showinfo
    if [ "$?" -ne 0 ]; then
        yum makecache &>/dev/null
        CommRetParse_LTFLIB "yum makecache &>/dev/null"
        cat "/etc/os-release" | grep "KylinSec OS Linux 3 (Qomolangma)"
        CommRetParse_LTFLIB "cat /etc/os-release| grep KylinSec OS Linux 3 (Qomolangma)"
        local milestone=$(cat /etc/.kyinfo | grep "milestone")
        local version_num=$(echo -e "${milestone}" | awk -F= '{print $2}' | sed 's/-[a-z].*//g' | sed 's/[A-Z]-[0-9].*//')
        rpm -q --provides "kylinsec-release" | grep "${version_num}"
        CommRetParse_LTFLIB "rpm -q --provides kylinsec-release| grep ${version_num}"
        lsb_release -a | grep "KylinSec OS release 3 (Qomolangma)"
        CommRetParse_LTFLIB "lsb_release -a | grep KylinSec OS release 3 (Qomolangma)"
    else
        cat "/etc/os-release" | grep "KylinSec OS 6"
        CommRetParse_LTFLIB "cat /etc/os-release| grep KylinSec OS 6"
    fi
}

#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
